<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Bulletin/classes/PhpFox_ComponentSmallBoard.class.php, $Author:  $ */



/** Display list bulletins
 * 
 * Parameters:
 *  1. oUser (mandatory) - user account object
 * 
 * @package module.bulletin
 * @version $Id: 
 *   PHPFox Team ()
 */
class PhpFox_Mod_Bulletin_ComponentSmallBoard extends BaseComponent
{
	function process()
	{	    
	    $oTpl = &$this->_oModule->getTemplate();
	    
	    if ( App::getParam('bFriendlyBoard') )
	    {
	    	$oSrvBulletin = $this->_oModule->getService('Bulletin');
		    $oSrvAccount = &App::getModuleService('Account', 'Security');
		    $oSrvFriend  = &App::getModuleService('Account', 'Friends');

		    $aCond = array();
        	
	    	$iPage = 1;
        	$iPageSize = App::getParam('public.account.small.board');
        	$sCnd = $oSrvFriend->getFriendsString( $oSrvAccount->getCurrentUser() );
        	
        	$aCond['user'] = ' IN ("'.App::getUser('user').'"'.($sCnd? ','.$sCnd:'').')';
        	
        	$sOrder = 'time DESC';
        	
        	list($aBulletin, $iCnt) = $oSrvBulletin->listBulletins($aCond, $iPage, $iPageSize, $sOrder);
			/*
        	$aBulletin = $this->oDatabase->getRows("
        		SELECT b.id, b.title, b.user, b.time 
        		FROM ". App::getT('board') ." AS b
        			JOIN " . App::getT('friends') . " AS f
        				ON f.user = '" . App::getUser('user') . "' AND f.friend = b.user
        		ORDER BY b.time DESC LIMIT 0,". App::getParam('public.account.small.board') ."");	        
			*/
        }
        else
        {
        	$aBulletin = $this->oDatabase->getRows("SELECT id, title, user, time FROM ". App::getT('board') ." ORDER BY time DESC LIMIT 0,". App::getParam('public.account.small.board') ."");	        
		}     

        foreach ($aBulletin as $i=>$aRes)
        {
            $aBulletin[$i]['bloc'] = true;
            $aBulletin[$i]['owner']  = (App::getUser('user') == $aRes['user']) ? true : false;
        }
        
        $oTpl->assignSrc(array(
                                'aBulletin'    => !empty($aBulletin) ? $aBulletin : false,
                                )
        );
        
        $oTpl->assign(array(
			                 
			                 'aErrors'		=> $this->getErrors(),
                             'sUserPicUrl' 	=> App::getParam('user.pic.url'),
			));
		
		$srcHtml = $oTpl->fetch('SmallBoard.html');
		return $srcHtml;
	}
}
?>